package com.qf.controller;

import com.qf.pojo.DtsStorage;
import com.qf.service.DtsStorageService;
import com.qf.util.ResponseUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.Map;

@RestController
@RequestMapping("/admin/storage")
public class DtsStorageController {
    @Autowired
    DtsStorageService storageService;
    @GetMapping("/list")
    public Object list(
            @RequestParam(value = "page",required = false, defaultValue = "1") Integer page,
            @RequestParam(value = "limit",required = false, defaultValue = "20") Integer limit,
            String name , String key, String sort, String order) {
        Map<String,Object> data = storageService.queryPage(page, limit,name,key,sort,order);
        return ResponseUtil.ok(data);
    }
    @PostMapping("/create")
    public Object create(MultipartFile file) throws Exception {
        byte[] bus = file.getBytes();
        DtsStorage storage = new DtsStorage();
        //name：原始文件名
        storage.setName(file.getOriginalFilename());
        //type：文件类型
        storage.setType(file.getContentType());
        //size：文件大小
        storage.setSize((int)file.getSize());
        storage = storageService.save(storage,bus);
        //响应前端
        return ResponseUtil.ok();
    }
}
